﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="robots" content="all,follow">
    <!-- Bootstrap CSS-->
    <link rel="stylesheet" href="static/vendor/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome CSS-->
    <link rel="stylesheet" href="static/vendor/font-awesome/css/font-awesome.min.css">
    <!-- Fontastic Custom icon font-->
    <link rel="stylesheet" href="static/css/fontastic.css">
    <!-- Google fonts - Poppins -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins:300,400,700">
    <!-- theme stylesheet-->
    <link rel="stylesheet" href="static/css/style.default.css" id="theme-stylesheet">
    <!-- Custom stylesheet - for your changes-->
    <link rel="stylesheet" href="static/css/custom.css">
    <link rel="stylesheet" href="static/css/fileinput.css">

    <!-- Favicon-->
    <link rel="shortcut icon" href="static/img/favicon.ico">
    <style>
        [v-cloak] {
            display: none;
        }
    </style>
    <!-- Tweaks for older IEs-->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
        <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script><![endif]-->
</head>

<body>
    <div id="app">
        <div class="page">
            <!-- Main Navbar-->
            <header class="header">
                <nav class="navbar">
                    <!-- Search Box-->
                    <div class="search-box">
                        <button class="dismiss"><i class="icon-close"></i></button>
                        <form id="searchForm" action="#" role="search">
                            <input type="search" placeholder="What are you looking for..." class="form-control">
                        </form>
                    </div>
                    <div class="container-fluid">
                        <div class="navbar-holder d-flex align-items-center justify-content-between">
                            <!-- Navbar Header-->
                            <div class="navbar-header">
                                <!-- Navbar Brand -->
                                <a href="index.html" class="navbar-brand d-none d-sm-inline-block">
                                    <div class="brand-text d-none d-lg-inline-block"><span>淘书斋后台管理</span></div>
                            </div>
                            <!-- Navbar Menu -->
                            <ul class="nav-menu list-unstyled d-flex flex-md-row align-items-md-center">
                                <!-- Search-->
                                <li class="nav-item d-flex align-items-center">
                                    <a href="#"></a>
                                </li>

                                <!-- Logout    -->
                                <li class="nav-item">
                                    <li @click="logout()">
                                        <a href="#" class="nav-link logout"> <span class="d-none d-sm-inline">退出</span><i class="fa fa-sign-out"></i></a>
                                    </li>
                                </li>
                            </ul>
                        </div>
                    </div>
                </nav>
            </header>
            <div class="page-content d-flex align-items-stretch">
                <!-- Side Navbar -->
                <nav class="side-navbar">
                    <!-- Sidebar Header-->
                    <div class="sidebar-header d-flex align-items-center">
                        <div class="avatar"><img src="static/img/gao.jpg" alt="..." class="img-fluid rounded-circle"></div>
                        <div class="title">
                            <h1 class="h4">{{adminName}}</h1>
                            <p>管理员</p>
                        </div>
                    </div>
                    <!-- Sidebar Navidation Menus--><span class="heading">管理</span>
                    <ul class="list-unstyled">
                        <li>
                            <a href="index.html"> <i class="icon-home"></i>首页</a>
                        </li>
                        <li class="active">
                            <a href="#bookDownDropdown" aria-expanded="false" data-toggle="collapse"> <i class="icon-interface-windows"></i>书本管理</a>
                            <ul id="bookDownDropdown" class="collapse list-unstyled ">
                                <li><a href="book.html">书本列表</a></li>
                                <li><a href="booktype.html">书本类型列表</a></li>
                            </ul>
                        </li>

                        <li>
                            <a href="#orderDownDropdown" aria-expanded="false" data-toggle="collapse"> <i class="icon-interface-windows"></i>订单管理</a>
                            <ul id="orderDownDropdown" class="collapse list-unstyled ">
                                <li><a href="order.html">订单列表</a></li>
                            </ul>
                        </li>

                        <li>
                            <a href="#userDownDropdown" aria-expanded="false" data-toggle="collapse"> <i class="icon-interface-windows"></i>用户管理</a>
                            <ul id="userDownDropdown" class="collapse list-unstyled ">
                                <li><a href="user.html">用户列表</a></li>

                            </ul>
                        </li>


                    </ul><span class="heading">设置</span>
                    <ul class="list-unstyled">
                        <li>
                            <a href="role.html"> <i class="icon-flask"></i>权限管理 </a>
                        </li>
                    </ul>
                </nav>
                <div class="content-inner">
                    <!-- Page Header-->
                    <header class="page-header">
                        <div class="container-fluid">
                            <h2 class="no-margin-bottom">淘书斋</h2>
                        </div>
                    </header>
                    <!-- Breadcrumb-->
                    <div class="breadcrumb-holder container-fluid">
                        <ul class="breadcrumb">
                            <li class="breadcrumb-item"><a href="order.html">书本列表</a></li>
                            <li class="breadcrumb-item active">更新书本 </li>
                        </ul>
                    </div>
                    <!-- Forms Section-->

                    <section class="forms">
                        <div class="container-fluid">
                            <div class="row">

                                <!-- Form Elements -->
                                <div class="col-lg-12">
                                    <div class="card">
                                        <div class="card-close">
                                            <div class="dropdown">
                                                <button type="button" id="closeCard5" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="dropdown-toggle"><i class="fa fa-ellipsis-v"></i></button>

                                            </div>
                                        </div>
                                        <div class="card-header d-flex align-items-center">
                                            <h3 class="h4">书本信息</h3>
                                        </div>
                                        <div class="card-body">
                                            <form class="form-horizontal">
                                                <div v-if="bookNameValid==='0'" class="form-group row">
                                                    <label class="col-sm-1 form-control-label">名称</label>
                                                    <div class="col-sm-6">
                                                        <input v-model="book.bookName" type="text" placeholder="请输入名称" class="form-control" @change="bookNameChange()">
                                                    </div>
                                                </div>

                                                <div v-else-if="bookNameValid==='1'" class="form-group row has-success">

                                                    <label class="col-sm-1 form-control-label">名称</label>
                                                    <div class="col-sm-6">
                                                        <input v-model="book.bookName" type="text" placeholder="请输入名称" class="form-control is-valid" @change="bookNameChange()">
                                                    </div>
                                                </div>

                                                <div v-else class="form-group row has-danger">

                                                    <label class="col-sm-1 form-control-label">名称</label>
                                                    <div class="col-sm-6">
                                                        <input v-model="book.bookName" type="text" placeholder="请输入名称" class="form-control is-invalid" @change="bookNameChange()">
                                                        <div class="invalid-feedback">请输入名称</div>
                                                    </div>
                                                </div>


                                                <div class="line "></div>
                                                <div v-if="bookCountValid==='0'" class="form-group row">
                                                    <label class="col-sm-1 form-control-label">数量</label>
                                                    <div class="col-sm-6">
                                                        <input v-model="book.bookCount" type="text" placeholder="请输入数量" class="form-control" @change="bookCountChange()">
                                                    </div>
                                                </div>

                                                <div v-else-if="bookCountValid==='1'" class="form-group row has-success">

                                                    <label class="col-sm-1 form-control-label">数量</label>
                                                    <div class="col-sm-6">
                                                        <input v-model="book.bookCount" type="text" placeholder="请输入数量" class="form-control is-valid" @change="bookCountChange()">
                                                    </div>
                                                </div>

                                                <div v-else class="form-group row has-danger">

                                                    <label class="col-sm-1 form-control-label">数量</label>
                                                    <div class="col-sm-6">
                                                        <input v-model="book.bookCount" type="text" placeholder="请输入数量" class="form-control is-invalid" @change="bookCountChange()">
                                                        <div class="invalid-feedback">请输入数字</div>
                                                    </div>
                                                </div>
                                                <div class="line "></div>

                                                <div v-if="bookPriceValid==='0'" class="form-group row">
                                                    <label class="col-sm-1 form-control-label">价格</label>
                                                    <div class="col-sm-6">
                                                        <input v-model="book.bookPrice" type="text" placeholder="请输入价格" class="form-control" @change="bookPriceChange()">
                                                    </div>
                                                </div>

                                                <div v-else-if="bookPriceValid==='1'" class="form-group row has-success">

                                                    <label class="col-sm-1 form-control-label">价格</label>
                                                    <div class="col-sm-6">
                                                        <input v-model="book.bookPrice" type="text" placeholder="请输入价格" class="form-control is-valid" @change="bookPriceChange()">
                                                    </div>
                                                </div>

                                                <div v-else class="form-group row has-danger">

                                                    <label class="col-sm-1 form-control-label">价格</label>
                                                    <div class="col-sm-6">
                                                        <input v-model="book.bookPrice" type="text" placeholder="请输入价格" class="form-control is-invalid" @change="bookPriceChange()">
                                                        <div class="invalid-feedback">请输入大于0的金额，且小数不超过2位</div>
                                                    </div>
                                                </div>

                                                <div class="line "></div>
                                                <div v-if="bookAuthorValid==='0'" class="form-group row">
                                                    <label class="col-sm-1 form-control-label">作者</label>
                                                    <div class="col-sm-6">
                                                        <input v-model="book.bookAuthor" type="text" placeholder="请输入作者" class="form-control" @change="bookAuthorChange()">
                                                    </div>
                                                </div>

                                                <div v-else-if="bookAuthorValid==='1'" class="form-group row has-success">

                                                    <label class="col-sm-1 form-control-label">作者</label>
                                                    <div class="col-sm-6">
                                                        <input v-model="book.bookAuthor" type="text" placeholder="请输入作者" class="form-control is-valid" @change="bookAuthorChange()">
                                                    </div>
                                                </div>

                                                <div v-else class="form-group row has-danger">

                                                    <label class="col-sm-1 form-control-label">作者</label>
                                                    <div class="col-sm-6">
                                                        <input v-model="book.bookAuthor" type="text" placeholder="请输入作者" class="form-control is-invalid" @change="bookAuthorChange()">
                                                        <div class="invalid-feedback">请输入作者</div>
                                                    </div>
                                                </div>

                                                <div class="line "></div>
                                                <div class="form-group row ">
                                                    <label class="col-sm-1 form-control-label ">商品类型</label>
                                                    <div class="col-sm-6">
                                                        <select v-model="typeSelected" @change="selectChange($event)" name="account " class="form-control mb-3">
                                                        
                              <option v-for="(item,index) in bookTypeList" :value="item.id">{{item.name}}</option>
                            </select>
                                                    </div>

                                                </div>
                                                <div class="line "></div>

                                                <div v-if="bookDetailValid==='0'" class="form-group row">
                                                    <label class="col-sm-1 form-control-label ">描述</label>
                                                    <div class="col-sm-9 ">
                                                        <textarea v-model="book.bookDetail" class="form-control" @change="bookDetailChange()" rows="6"></textarea>
                                                        <small class="help-block-none ">请输入商品描述</small>
                                                    </div>
                                                </div>

                                                <div v-else-if="bookDetailValid==='1'" class="form-group row has-success">

                                                    <label class="col-sm-1 form-control-label">描述</label>
                                                    <div class="col-sm-9 ">
                                                        <textarea v-model="book.bookDetail" class="form-control is-valid" @change="bookDetailChange()" rows="6"></textarea>
                                                    </div>
                                                </div>

                                                <div v-else class="form-group row has-danger">
                                                    <label class="col-sm-1 form-control-label">描述</label>
                                                    <div class="col-sm-9 ">
                                                        <textarea v-model="book.bookDetail" class="form-control is-invalid" @change="bookDetailChange()" rows="6"></textarea>
                                                        <div class="invalid-feedback">请输入商品描述</div>
                                                    </div>
                                                </div>
                                                <div class="line "></div>
                                                <div class="form-group row ">
                                                    <label class="col-sm-1 form-control-label ">封面</label>
                                                    <div class="col-sm-9 ">
                                                        <div class="file-loading">
                                                            <input id="uploadCover" name="file" type="file" multiple class="file-loading">
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="line "></div>

                                                <div class="form-group row ">
                                                    <label class="col-sm-1 form-control-label ">详细图片</label>
                                                    <div class="col-sm-9 ">
                                                        <div class="file-loading" id="imgFile">
                                                            <input id="uploadFile" name="file" type="file" multiple class="file">
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="line "></div>
                                                <!-- <div class="form-group row has-success ">
                                                <label class="col-sm-3 form-control-label ">Input with success</label>
                                                <div class="col-sm-9 ">
                                                    <input type="text " class="form-control is-valid ">
                                                </div>
                                            </div>
                                            <div class="line "></div>
                                            <div class="form-group row has-danger ">
                                                <label class="col-sm-3 form-control-label ">Input with error</label>
                                                <div class="col-sm-9 ">
                                                    <input type="text " class="form-control is-invalid ">
                                                    <div class="invalid-feedback ">Please provide your name.</div>
                                                </div>
                                            </div>
                                            <div class="line "></div> -->

                                                <!-- <div class="form-group row ">
                                                <label class="col-sm-3 form-control-label ">Button addons</label>
                                                <div class="col-sm-9 ">
                                                    <div class="form-group ">
                                                        <div class="input-group ">
                                                            <div class="input-group-prepend ">
                                                                <button type="button " class="btn btn-primary ">Go!</button>
                                                            </div>
                                                            <input type="text " class="form-control ">
                                                        </div>
                                                    </div>
                                                    <div class="form-group ">
                                                        <div class="input-group ">
                                                            <input type="text " class="form-control ">
                                                            <div class="input-group-append ">
                                                                <button type="button " class="btn btn-primary ">Go!</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div> -->

                                                <div class="form-group row ">
                                                    <div class="col-sm-4 offset-sm-3 ">
                                                        <button type="button" @click="back()" class="btn btn-secondary "></a>返回</button>
                                                        <button type="button" class="btn btn-primary" @click="save()">保存</button>
                                                    </div>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </section>

                    <!-- Page Footer-->
                    <footer class="main-footer ">
                        <div class="container-fluid ">
                            <div class="row ">
                                <div class="col-sm-6 ">
                                    <p class="weui-footer__text">Copyright © 2019 <a style="color:#3f8b81" href="#">抓娃小组</a>&nbsp版权所有</p>
                                </div>
                                <div class="col-sm-6 text-right ">
                                    <p></p>
                                    <!-- Please do not remove the backlink to us unless you support further theme's development at https://bootstrapious.com/donate. It is part of the license conditions. Thank you for understanding :)-->
                                </div>
                            </div>
                        </div>
                    </footer>
                </div>
            </div>
        </div>
    </div>
    <!-- JavaScript files-->
    <script src="static/vendor/jquery/jquery.min.js "></script>
    <script src="static/vendor/popper.js/umd/popper.min.js ">
    </script>
    <script src="static/vendor/bootstrap/js/bootstrap.min.js "></script>
    <script src="static/vendor/jquery.cookie/jquery.cookie.js ">
    </script>
    <script src="static/vendor/chart.js/Chart.min.js "></script>
    <script src="static/vendor/jquery-validation/jquery.validate.min.js "></script>
    <!-- Main File-->
    <script src="static/js/front.js "></script>
    <script src="static/js/fileinput.js "></script>
    <script src="https://cdn.bootcss.com/bootstrap-fileinput/4.3.5/js/locales/zh.min.js "></script>
    <script src="static/node_modules/vue/dist/vue.js"></script>
    <script>
    </script>

    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                adminName: '',
                bookId: '',
                msg: 'hello',
                bookImgArr: [],
                bookImgSubmit: [],
                bookImgDelete: [],
                uploadedImg: [],
                bookImgString: '',
                bookImgDeleteString: '',
                priviewDeleteList: [],
                bookCoverArr: [],
                bookCoverString: '',
                priviewCoverDeleteList: [],
                uploadCover: [],
                bookCoverDelete: [],
                //服务器:http://47.100.136.219
                serverIp: 'http://47.100.136.219',
                ifLocal: false,

                book: {
                    bookId: '',
                    bookAuthor: '',
                    bookCount: '',
                    bookCover: '',
                    bookDetail: '',
                    bookImg: '',
                    bookName: '',
                    bookPrice: '',
                    bookTypeId: '',
                    detailImg: '',

                },
                priviewData: {},
                bookTypeList: [{
                    'id': '1',
                    'name': '计算机',
                }, {
                    'id': '2',
                    'name': '科学',
                }, {
                    'id': '3',
                    'name': '经济',
                }, {
                    'id': '4',
                    'name': '军事',
                }, {
                    'id': '5',
                    'name': '哲学',
                }, {
                    'id': '6',
                    'name': '数学',
                }, {
                    'id': '7',
                    'name': '航空',
                }, {
                    'id': '8',
                    'name': '文学',
                }, {
                    'id': '9',
                    'name': '艺术',
                }, {
                    'id': '10',
                    'name': '语言',
                }, ],

                typeSelected: '',
                bookNameValid: '0',
                bookCountValid: '0',
                bookPriceValid: '0',
                bookAuthorValid: '0',
                bookDetailValid: '0',

            },
            mounted() {
                let _this = this;

                if (this.ifLocal) {
                    this.serverIp = "http://localhost";
                }


                $.ajax({
                    type: "GET",
                    url: _this.serverIp + ":8088/boot/admincommon/info",
                    success: function(response) {
                        if (response.code == 200) {
                            console.log(response.data);
                            _this.adminName = response.data.data.principal.username
                        }
                    },

                });


                _this.bookImgString = getQueryString('img');
                _this.bookCoverString = getQueryString('cover');
                _this.bookId = getQueryString('id');
                $.ajax({
                    type: "GET",
                    url: _this.serverIp + ":8088/boot/adminbook/book/" + _this.bookId,
                    success: function(response) {
                        if (response.code == 200) {
                            console.log(response.data.book);
                            _this.book = response.data.book;
                            _this.typeSelected = response.data.book.bookTypeId;


                        } else if (response.code == 403) {
                            alert(response.msg);

                        }
                    }
                });


                _this.bookImgArr = _this.bookImgString.split(';');

                if (_this.bookCoverString.indexOf("http") < 0) {
                    _this.bookCoverString = "http:" + _this.bookCoverString;

                }
                _this.bookCoverArr.push(_this.bookCoverString);


                for (i = 0; i < _this.bookImgArr.length; i++) {

                    if (_this.bookImgArr[i].indexOf("http") < 0) {
                        _this.bookImgArr[i] = "http:" + _this.bookImgArr[i];

                    }
                    _this.bookImgSubmit.push(_this.bookImgArr[i]);
                    _this.priviewData = {
                        caption: i + ".jpg",
                        size: 329892,
                        width: "120px",
                        url: _this.serverIp + ":8088/boot/adminbook/deleteimg",
                        key: i,
                        extra: {
                            id: i,
                            url: _this.bookImgArr[i]
                        }
                    };

                    _this.priviewDeleteList.push(_this.priviewData);
                    _this.priviewData = {

                        size: 329892,
                        width: "120px",
                        url: _this.serverIp + ":8088/boot/adminbook/deleteimg",
                        key: 0,
                        extra: {
                            id: '',
                            url: '',

                        }
                    }

                }




                _this.priviewCoverDeleteList.push({
                    caption: "cover.jpg",
                    size: 329892,
                    width: "120px",
                    url: _this.serverIp + ":8088/boot/adminbook/deleteimg",
                    key: 100,
                    extra: {
                        id: '100',
                        url: _this.bookCoverString
                    }
                });

                $('#uploadCover').fileinput({
                    language: 'zh',
                    　　　　　　　　 //使用中文
                    theme: 'fa',

                    showUpload: true,
                    showRemove: false,
                    　　　　　　 //upload按钮不显示
                    uploadUrl: _this.serverIp + ':8088/boot/adminbook/uploadimg', //服务器url调用路径
                    allowedFileExtensions: ['jpg', 'png', 'gif'],
                    　　　　 //允许的文件格式

                    overwriteInitial: false,
                    initialPreviewAsData: true,
                    initialPreview: _this.bookCoverArr, //这里配置需要初始展示的图片连接数组，字符串类型的，通常是通过后台获取后然后组装成数组直接赋给initialPreview就行了
                    initialPreviewConfig: _this.priviewCoverDeleteList,


                    validateInitialCount: true, //开启计数功能
                    maxFileSize: 2048,
                    　　　　　　　　　　　　　　　　　　　　 //文件最大尺寸
                    maxFileCount: 1, //文件同时上传最大数量

                    msgFilesTooMany: "上传的最大数量为1张！"　　　　　　　　　　　　　　　　　　　　　

                }).on('filepredelete', function(event, key, jqXHR, data) {
                    console.log('Key = ' + key);

                    console.log(data);
                    console.log("删除原始的封面");
                    _this.bookImgDelete.push(data.url);
                    _this.bookCoverString = '';

                }).on('filepreupload', function(event, data, previewId, index) { //上传中

                }).on("fileuploaded", function(event, data, previewId, index) { //一个文件上传成功
                    var response = data.response;

                    var bookImg = {
                        id: '',
                        url: ''
                    };
                    console.log(response);
                    bookImg.id = previewId;
                    bookImg.url = response.data.url;
                    _this.uploadCover.push(bookImg);
                    _this.bookCoverString = response.data.url;
                    console.log("返回上传封面后的url");
                    console.log(_this.bookCoverString);
                }).on('fileerror', function(event, data, msg) { //一个文件上传失败
                    console.log('文件上传失败！' + data);
                }).on('filesuccessremove', function(event, previewId, extra) {　　　　　　 //在移除事件里取出所需数据，并执行相应的删除指令
                    _this.bookCoverString = '';
                    console.log("删除详细的封面");
                    for (i = 0; i < _this.uploadCover.length; i++) {
                        if (_this.uploadCover[i].id == previewId) {

                            _this.bookImgDelete.push(_this.uploadCover[i].url);

                            _this.uploadCover.splice(_this.uploadCover.indexOf(_this.uploadCover[i]), 1);

                        }
                    }
                });



                $('#uploadFile').fileinput({
                    language: 'zh',
                    　　　　　　　　 //使用中文
                    theme: 'fa',

                    showUpload: true,
                    showRemove: false,
                    　　　　　　 //upload按钮不显示
                    uploadUrl: _this.serverIp + ':8088/boot/adminbook/uploadimg', //服务器url调用路径
                    allowedFileExtensions: ['jpg', 'png', 'gif'],
                    　　　　 //允许的文件格式

                    overwriteInitial: false,
                    initialPreviewAsData: true,
                    initialPreview: _this.bookImgArr, //这里配置需要初始展示的图片连接数组，字符串类型的，通常是通过后台获取后然后组装成数组直接赋给initialPreview就行了
                    initialPreviewConfig: _this.priviewDeleteList,


                    validateInitialCount: true, //开启计数功能
                    maxFileSize: 2048,
                    　　　　　　　　　　　　　　　　　　　　 //文件最大尺寸
                    maxFileCount: 3, //文件同时上传最大数量

                    msgFilesTooMany: "上传的最大数量为3张！"　　　　　　　　　　　　　　　　　　　　　

                }).on('filepredelete', function(event, key, jqXHR, data) {
                    console.log('Key = ' + key);

                    console.log("删除原始的详细图片");

                    for (i = 0; i < _this.bookImgSubmit.length; i++) {
                        if (_this.bookImgSubmit[i] == data.url) {
                            _this.bookImgDelete.push(_this.bookImgSubmit[i]);
                            _this.bookImgSubmit.splice(_this.bookImgSubmit.indexOf(_this.bookImgSubmit[i]), 1);

                        }
                    }

                }).on('filepreupload', function(event, data, previewId, index) { //上传中

                }).on("fileuploaded", function(event, data, previewId, index) { //一个文件上传成功
                    var response = data.response;

                    var bookImg = {
                        id: '',
                        url: ''
                    };
                    console.log(response);
                    bookImg.id = previewId;
                    bookImg.url = response.data.url;
                    _this.uploadedImg.push(bookImg);
                    _this.bookImgSubmit.push(
                        response.data.url
                    );

                    console.log(_this.bookImgSubmit);
                }).on('fileerror', function(event, data, msg) { //一个文件上传失败
                    console.log('文件上传失败！' + data);
                }).on('filesuccessremove', function(event, previewId, extra) {　　　　　　 //在移除事件里取出所需数据，并执行相应的删除指令

                    console.log("删除上传后的详细图片");
                    for (i = 0; i < _this.uploadedImg.length; i++) {
                        if (_this.uploadedImg[i].id == previewId) {

                            _this.bookImgDelete.push(_this.uploadedImg[i].url);
                            _this.bookImgSubmit.splice(_this.bookImgSubmit.indexOf(_this.uploadedImg[i].url), 1);
                            _this.uploadedImg.splice(_this.uploadedImg.indexOf(_this.uploadedImg[i]), 1);

                        }
                    }
                    console.log(_this.bookImgSubmit);
                    for (i = 0; i < _this.bookImgSubmit.length; i++) {

                        console.log(_this.bookImgSubmit[i]);

                    }

                });



            },


            methods: {
                logout() {
                    let _this = this;
                    $.ajax({
                        url: _this.serverIP + ':8088/boot/logout',
                        type: 'POST',
                        success: function(res, status) {
                            console.log(res);
                            location.href = "login.html";

                        },
                        error: function(res, status) {
                            console.log(res);
                        }
                    });
                },

                back() {
                    location.href =
                        "book.html";
                },

                selectChange(e) {
                    console.log(e.target.value) // 选择项的value
                    this.book.bookTypeId = e.target.value;

                },

                save() {
                    let _this = this;
                    _this.book.detailImg = '';
                    _this.book.bookCover = _this.bookCoverString;
                    _this.book.bookImg = _this.bookCoverString;
                    console.log(_this.book);
                    console.log("最后提交的照片url：");
                    console.log(_this.bookImgSubmit);
                    for (i = 0; i < _this.bookImgSubmit.length; i++) {
                        if (i + 1 == _this.bookImgSubmit.length) {
                            _this.book.detailImg += _this.bookImgSubmit[i];
                        } else {
                            _this.book.detailImg += _this.bookImgSubmit[i] + ";";
                        }

                    }
                    console.log("最后删除的照片url：");
                    console.log(this.bookImgDelete);
                    for (i = 0; i < _this.bookImgDelete.length; i++) {
                        if (i + 1 == _this.bookImgDelete.length) {
                            _this.bookImgDeleteString += _this.bookImgDelete[i];
                        } else {
                            _this.bookImgDeleteString += _this.bookImgDelete[i] + ";";
                        }

                    }

                    if (_this.bookNameValid == "-1" || _this.bookCountValid == "-1" || _this.bookPriceValid == "-1" || _this.bookAuthorValid == "-1" || _this.bookDetailValid == "-1") {
                        alert("请填写正确信息再保存!");
                        return;
                    }

                    if (_this.book.bookCover == "") {
                        alert("请至少上传一张封面图片!");
                        return;
                    }

                    if (_this.book.detailImg == "") {
                        alert("请至少上传一张详情图片!");
                        return;
                    }

                    console.log("开始提交数据");
                    $.ajax({
                        type: "PUT",
                        url: _this.serverIp + ":8088/boot/adminbook/book",
                        data: JSON.stringify(_this.book), //必要
                        dataType: "json",
                        contentType: "application/json",
                        success: function(response) {
                            if (response.code == 200) {
                                console.log(response.data);

                                if (_this.bookImgDelete.length > 0) {
                                    console.log("开始删除数据");
                                    $.ajax({
                                        type: "POST",
                                        url: _this.serverIp + ":8088/boot/adminbook/deletelocateimg",
                                        data: {
                                            urlString: _this.bookImgDeleteString
                                        },
                                        success: function(response2) {
                                            if (response2.code == 200) {
                                                console.log(response2.data);

                                            } else if (response2.code == 403) {
                                                alert(response2.msg);

                                            }
                                        }
                                    });
                                }

                                location.href =
                                    "book-detail.html?id=" + _this.book.bookId;


                            } else if (response.code == 403) {
                                alert(response.msg);

                            }
                        }
                    });


                },

                bookNameChange() {
                    let _this = this;

                    if (_this.book.bookName == "") {
                        _this.bookNameValid = "-1";
                    } else {
                        _this.bookNameValid = "1";
                    }
                },
                bookCountChange() {
                    let _this = this;
                    var bookCount = /^[0-9]*$/;
                    if (!bookCount.test(_this.book.bookCount)) {
                        _this.bookCountValid = "-1";
                    } else {
                        _this.bookCountValid = "1";
                    }
                },

                bookPriceChange() {
                    let _this = this;
                    var bookPrice = /^([1-9][0-9]*)+(.[0-9]{1,2})?$/;
                    if (!bookPrice.test(_this.book.bookPrice)) {
                        _this.bookPriceValid = "-1";
                    } else {
                        _this.bookPriceValid = "1";
                    }
                },

                bookAuthorChange() {
                    let _this = this;

                    if (_this.book.bookAuthor == "") {
                        _this.bookAuthorValid = "-1";
                    } else {
                        _this.bookAuthorValid = "1";
                    }
                },
                bookDetailChange() {
                    let _this = this;

                    if (_this.book.bookDetail == "") {
                        _this.bookDetailValid = "-1";
                    } else {
                        _this.bookDetailValid = "1";
                    }
                },



            },



        });

        function getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        }
    </script>
</body>